<?php
/**
 * Created by JetBrains PhpStorm.
 * User: GMC
 * Date: 10/3/13
 * Time: 2:20 PM
 * To change this template use File | Settings | File Templates.
 */

class WidgetService extends CWidget {
    public $model;

    public function init() {
        $service_cache = Yii::app()->cache->get('service_cache');
        if ($service_cache == null || count($service_cache) == 0) {
            $services = Ads::model()->findAll(array(
                'select' => 'ads_id, ads_name, description, url, image_path',
                'condition' => 'position = :position',
                'limit' => 24,
                'params' => array(':position' => 'dichvu')
            ));
            Yii::app()->cache->set('service_cache', $services, 'service_cache_time');
            $service_cache = Yii::app()->cache->get('service_cache');
        }
        $this->model = $service_cache;
    }

    public function run() {
        return CWidget::render('widgetService', array('model' => $this->model));
    }
}